from typing import List
from django.http import HttpRequest
from ninja import NinjaAPI
from ninja_crud import views, viewsets

from .models import SKU
from .schema import SKUSchemaOut

api = NinjaAPI()


class SKUViewSet(viewsets.APIViewSet):
    """
    TODO：对于如何获取路径参数，过滤等需要看文档后再制作
    """
    api = api
    model = SKU
    # default_request_body = SKUSchemaIn
    default_response_body = SKUSchemaOut

    list_skus = views.ListView()
    create_sku = views.CreateView()
    read_sku = views.ReadView()
    update_sku = views.UpdateView()
    delete_sku = views.DeleteView()


# 除了视图集管理的 CRUD 操作外，
# api 或路由器可以按照标准的 Django Ninja 方式使用
@api.get("/statistics/", response=dict)
def get_sku_statistics(request: HttpRequest):
    return {"total": SKU.objects.count()}
